package com.lq.whattoeattoday.controller;

import cn.hutool.json.JSONUtil;
import com.lq.whattoeattoday.Enum.TypeEnum;
import com.lq.whattoeattoday.pojo.FoodPojo;
import com.lq.whattoeattoday.util.FoodUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Api(tags = "接口")
@RestController
@RequestMapping("api")
public class IndexController
{
    @Resource
    private FoodUtil foodUtil;


    @ApiOperation("获取今天吃啥")
    @RequestMapping("randomDishes")
    public FoodPojo randomDishes(
            @ApiParam("用户的open id")
            String openId,
            @ApiParam("类别")
            Integer type)
    {
        Assert.notNull(openId, "openId不能为空");
        Assert.notNull(type, "type不能为空");
        return foodUtil.getRandomFood(type, openId);
    }

    @ApiOperation("菜品类别查询")
    @RequestMapping("menuCategoryInquiry")
    public String menuCategoryInquiry()
    {
        List<Map<String, Object>> collect = Arrays.stream(TypeEnum.values()).map((i) ->
                                                                                 {
                                                                                     Map<String, Object> map = new HashMap<>();
                                                                                     map.put("name", i.getName());
                                                                                     map.put("title", i.getTitle());
                                                                                     map.put("type", i.getType());
                                                                                     return map;
                                                                                 }).collect(Collectors.toList());
        return JSONUtil.toJsonStr(collect);
    }
}
